package com.dimples.dd.xxl.job.plus.discovery.nacos;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.nacos.api.naming.NamingService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Component;

/**
 * nacos namingService-spring cloud
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/10/18
 */
@Component
@ConditionalOnClass({NacosServiceManager.class})
@RequiredArgsConstructor
public class CloudNamingServiceHolder implements NamingServiceHolder {

    private final NacosServiceManager nacosServiceManager;

    private final NacosDiscoveryProperties nacosDiscoveryProperties;

    @Override
    public NamingService get() {
        return nacosServiceManager.getNamingService();
    }

    @Override
    public String getExecutorAddress() {
        return nacosDiscoveryProperties.getIp() + ":" + nacosDiscoveryProperties.getPort();
    }

    @Override
    public String getServiceName() {
        return nacosDiscoveryProperties.getService();
    }
}
